package xcu.lxj.nettychat.user.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xcu.lxj.nettychat.common.domain.vo.request.CursorPageBaseReq;
import xcu.lxj.nettychat.common.domain.vo.request.PageBaseReq;
import xcu.lxj.nettychat.common.domain.vo.response.ApiResult;
import xcu.lxj.nettychat.common.domain.vo.response.CursorPageBaseResp;
import xcu.lxj.nettychat.common.domain.vo.response.PageBaseResp;
import xcu.lxj.nettychat.common.utils.RequestHolder;
import xcu.lxj.nettychat.user.domain.vo.request.friend.FriendApplyReq;
import xcu.lxj.nettychat.user.domain.vo.request.friend.FriendApproveReq;
import xcu.lxj.nettychat.user.domain.vo.request.friend.FriendCheckReq;
import xcu.lxj.nettychat.user.domain.vo.request.friend.FriendDeleteReq;
import xcu.lxj.nettychat.user.domain.vo.response.friend.FriendApplyResp;
import xcu.lxj.nettychat.user.domain.vo.response.friend.FriendCheckResp;
import xcu.lxj.nettychat.user.domain.vo.response.friend.FriendResp;
import xcu.lxj.nettychat.user.domain.vo.response.friend.FriendUnreadResp;
import xcu.lxj.nettychat.user.service.inter.FriendService;

/**
 * @Author XinJian Lei
 * @Date 2024/10/2 20:00
 * @Version 1.0
 */
@RestController
//@Api(tags = "好友相关接口")
@Slf4j
@RequestMapping("/friend")
@Tag(name = "好友相关的接口")
public class FriendController {

    @Autowired
    private FriendService friendService;

    @PostMapping("/check")
    @Operation(summary="批量判断是否是自己好友")
    public ApiResult<FriendCheckResp> check(@RequestBody @Valid FriendCheckReq request) {
        Long uid = RequestHolder.get().getUid();
        return ApiResult.success(friendService.check(uid, request));
    }

    @PostMapping("/apply")
    @Operation(summary="申请好友")
    public ApiResult<Void> apply(@Valid @RequestBody FriendApplyReq request) {
        Long uid = RequestHolder.get().getUid();
        friendService.apply(uid, request);
        return ApiResult.success();
    }

    @DeleteMapping()
    @Operation(summary="删除好友")
    public ApiResult<Void> delete(@Valid @RequestBody FriendDeleteReq request) {
        Long uid = RequestHolder.get().getUid();
        friendService.deleteFriend(uid, request.getTargetUid());
        return ApiResult.success();
    }

    @PostMapping("/apply/page")
    @Operation(summary="好友申请列表")
    public ApiResult<PageBaseResp<FriendApplyResp>> page(@RequestBody @Valid PageBaseReq request) {
        Long uid = RequestHolder.get().getUid();
        return ApiResult.success(friendService.pageApplyFriend(uid, request));
    }

    @GetMapping("/apply/unread")
    @Operation(summary="申请未读数")
    public ApiResult<FriendUnreadResp> unread() {
        Long uid = RequestHolder.get().getUid();
        return ApiResult.success(friendService.unread(uid));
    }

    @PutMapping("/apply")
    @Operation(summary="审批同意")
    public ApiResult<Void> applyApprove(@Valid @RequestBody FriendApproveReq request) {
        friendService.applyApprove(RequestHolder.get().getUid(), request);
        return ApiResult.success();
    }

    @PostMapping("/page")
    @Operation(summary="联系人列表")
    public ApiResult<CursorPageBaseResp<FriendResp>> friendList(@RequestBody @Valid CursorPageBaseReq request) {
        Long uid = RequestHolder.get().getUid();
        return ApiResult.success(friendService.friendList(uid, request));
    }

}
